package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.MessageDTO;
import com.iflytek.dto.PageDTO;
import com.iflytek.service.MessageService;
import com.iflytek.vo.MessageVO;
import com.iflytek.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/message")
public class MessageController{
    @Resource
    public MessageService messageService;

    /**
     * 查询所有留言（非分页）findAll
     * @return
     */
    @ApiOperation("查询全部")
    @GetMapping("")
    Result<List<MessageVO>> findAll() {
        return messageService.findAll();
    }

    /**
     * 保存留言save
     * @param dto
     * @return
     */
    @ApiOperation("保存")
    @PostMapping("")
    Result<Boolean> saveMessage(@RequestBody MessageDTO dto) {
        return messageService.saveMessage(dto);
    }

    /**
     * 更新留言信息update
     * @param dto
     * @return
     */
    @ApiOperation("更新")
    @PutMapping("")
    Result<Boolean> updateMessage(@RequestBody MessageDTO dto) {
        return messageService.updateMessage(dto);
    }

    /**
     * 留言分页查询findPage
     * @param dto
     * @return
     */
    @ApiOperation("分页")
    @GetMapping("/page")
    Result<PageVO<MessageVO>> findPage(PageDTO<MessageDTO> dto) {
        return messageService.findPage(dto);
    }

    /*
    *关联id获取留言信息
    *
     */
    @ApiOperation("根据关联id获取留言信息")
    @GetMapping("/foreign/{id}")
    Result<List<MessageVO>> findByForeignId(@PathVariable("id") Integer foreignId){
        return messageService.findByForeignId(foreignId);
    }


    /**
     * 留言分页查询findById
     * @param id
     * @return
     */
    @ApiOperation("根据id查")
    @PostMapping("/{id}")
    Result<MessageVO> findById(@PathVariable("id") Integer id) {
        return messageService.findById(id);
    }

    /**
     * 根据id删除留言deleteById
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    Result<MessageVO> deleteById(@PathVariable("id") Integer id) {
        return messageService.deleteById(id);
    }

}